import actions from "@/actions";
import TableLyout from '@/components/commonPublic/tableLyout.vue'
import TableData from "@/components/commonPublic/el-table"; //主页面列表

import {
    getPierProjectPageLists, // 基桩工程信息查询页面-列表页接口
    getPierProjectPageList,
    getPierProjectStatisticInfo, // 基桩工程信息查询页面-基桩统计信息接口
    getPierProjectTaskLists, // 基桩工程信息查询页面-查询基桩任务接口
    getPierTaskByFid, //基桩检测信息编辑/查询页面-基桩检测任务详情页接口
    submitPierProject, //提交
    deletePierProjectByFid, //删除
} from "@/api/request.js";
import publicForm from "@/components/PCManage/fromCom.vue"; //弹框form

// import RingEcharts1 from "@/components/public/project"; //建设项目进场材料外委情况动态统计
// import peiNum from "@/components/public/peiNum"; //建设项目进场材料外委情况动态统计
// import pieStatitic from "@/components/public/pieStatitic"; //建设项目进场材料外委情况动态统计
import formJs from "./regexDetail.js"; //新增弹框配置项
import messageBox from "@/components/public/messageBox"; //弹框

import engPage from "@/components/PCManage/engPage"; //建设项目进场材料外委情况动态统计

export default {
    name: "Engineering",
    data() {
        return {
            names: "Engineering",
            projectsObj: [], //项目名
            tendersObj: [],
            falgId: null,
            editLoading: false,
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            btnObj: [{
                visible: true, // 是否展示出来
                title: "新增",
                name: this.yj_edit,
                order: 0
            }, {
                visible: true, // 是否展示出来
                title: "编辑",
                name: this.yj_edit,
                order: 1
            }, {
                visible: true, // 是否展示出来
                title: "提交",
                name: this.yj_submit,
                order: 2
            }, {
                visible: true, // 是否展示出来
                title: "删除",
                name: this.yj_delete,
                order: 3
            }, {
                visible: true, // 是否展示出来
                title: "查看",
                name: this.yj_edit,
                order: 4,
            }],
            formData: {
                fId: "", // 工程信息fid  有值时表示修改  其余表示新增
                fCompanyid: "", // 施工单位id
                fCompanyname: "", // 施工单位名称
                fProjectid: "", // 项目id
                fProjectname: "", // 项目名称
                fEngineeringname: "", // 工程名称
                fEngineeringlocation: "", // 工程地点
                fEngineeringinfo: "", // 工程信息简述
                fDesignfile: "", // 设计资料文件id
                fPiercount: "", // 墩台数量
                fFoundationcount: "", // 基桩数量
                fRegistrantid: "", // 登记人id
                fRegistrantname: "", // 登记人名称
                fRegistdates: "", // 登记时间
                // 当前用户数据
                userId: "", // 当前登陆用户id
                userName: "", // 当前登陆用户名称
                recordfiles: [], //删除文件id集合--修改时传
            },
            // 列表
            getList: {
                fprojectid: "",
                fCompanyid: null, //机构id
                fUserid: null, //当前登录用户id
                sublevel: "1", //查看下级  1是0否
                page: 1, //页码
                pageSize: 15, //每页条数
                keyWord: "", // 选择状态
            },
            currentRowId: null, //点击当前数据信息
            msgTip: "请先选中数据行！",
            msgType: 1,
            showMsgBox: false,




            fFileName: "",
            pdfUrl: "",
            fPhotofilelist: [], //检测记录表文件集合
            samllTable: [], //检测任务信息列表
            picsfile: [], //现场照片
            exceptionfiles: [], //异常资料
            checkfiles: [], //检测资料资料
            handlerfiles: [], //处理照片
            lrCheckPiertask: {},
            checkFile: [], //本次检测附件资料信息
            lrCheckPierfoundation: {}, // 基桩检测表格信息集合
            activeIndex: "1",
            dis: true,
            formLabelWidth1: "80px",
            statisticInfo: {}, //左侧基桩统计信息
            rateInfo: [], //右侧折线图数据

            fEquipmentname: [], //已选主要仪器设备

            dialogText: "",

            equipmentDetailId: null, //列表页id
            equipmentDetailIds: null, //检测任务信息列表页id

            sample: "",

            fId: null, //当前数据fId
            loading: false,
            dialogTableVisible: false,
            formLabelWidth: "150px",
            treeData: [],
            tableData: [],
            companyId: null,
            loadingDialog: false,
            currentRowId: "",
            treelength: false,
        };
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        engPage,
        messageBox,

    },
    mounted() {
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
            this.getList.fUserid = this.userInfo.id;

        }, true);

        // this.getList.fUserid = this.userInfo.id;
        if (JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"))) {
            var getListStorage = JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"));
            this.getList = getListStorage
            if (getListStorage.fprojectid != "") {}
            this.yj_searchForm(this.getList)
        } else {
            this.yj_searchForm(this.getList)
        }
        this.getPierProjectStatisticInfo()

    },
    methods: {
        // 重置按钮
        reset(e) {
            this.getList = this.$options.data.call(this).getList
            this.getList.fprojectid = e
        },
        confirmMsg() {
            this.showMsgBox = false;
        },
        // 新增/编辑
        yj_edit(num) {
            if (num == 0) {
                // 新增
                if (this.getList.fUserid != "System") {
                    this.$router.push({
                        path: "/pcManage/engineeringDetail",
                        query: {
                            // data: JSON.stringify(this.getList),
                            status: num
                        },
                    });

                } else {
                   
                    this.$message.warning({
                        content:"该用户无法新增",
                        duration: 1000
                    });
                }
            } else if (num == 1) {
                // 编辑
                if (this.currentRow != null) {
                    this.$router.push({
                        path: "/pcManage/engineeringDetail",
                        query: {
                            data: JSON.stringify(this.currentRow),
                            status: num
                        },
                    });
                } else {
                    this.$message.warning({
                        content:"请先选择需要编辑的数据",
                        duration: 1000
                    });
                    // this.showMsgBox = true;
                }
                // this.editText();
            } else if (num == 4) {
                if (this.currentRow != null) {
                    this.$router.push({
                        path: "/pcManage/engineeringDetail",
                        query: {
                            data: JSON.stringify(this.currentRow),
                            status: num
                        },
                    });
                } else {
                    this.$message.warning({
                        content:"请选择需要查看的数据",
                        duration: 1000
                    });
                }
            }
        },

        // 提交
        yj_submit(id) {

            if (this.currentRow != null) {
                this.loading = true;
                submitPierProject({
                        fId: this.currentRow.fId
                    })
                    .then((res) => {
                        if (res.errcode == 0) {
                            this.loading = false;
                            this.yj_searchForm(this.getList);
                        } else {
                            this.showMsgBox = true;
                            this.msgTip = "提交失败"
                            this.loading = false;
                            return false;
                        }
                    })
                    .catch(() => {
                        this.loading = false;
                        console.log("提交失败");
                    });

            } else {
                this.$message.warning({
                    content:"请选择需要提交的数据",
                    duration: 1000
                });
            }
        },
        // 删除
        yj_delete(id) {


            if (this.currentRow != null) {
                this.loading = true;

                deletePierProjectByFid({
                        fId: this.currentRow.fId
                    })
                    .then((res) => {
                        if (res.errcode == 0) {
                            this.loading = false;
                            this.yj_searchForm(this.getList);

                        } else {
                            // this.showMsgBox = true;
                            // this.msgTip = "删除失败"
                            this.$message.warning({
                                content:"删除失败"+ res.msg,
                                duration: 1000
                            });
                            this.loading = false;
                        }
                    })
                    .catch(() => {
                        console.log("删除失败");
                        this.loading = false;
                    });


            } else {
                // this.showMsgBox = true;
                this.$message.warning({
                    content:"请选择需要删除的数据",
                    duration: 1000
                });
            }
        },
        openPdfs1(v) {
            this.dialogPdf = true;
            this.pdfUrl = v.url;
            this.fFileName = v.fFileName;
        },
        // 检测任务信息列表
        getPierProjectTaskLists() {
            this.samllTable = [];
            this.lrCheckPiertask = {};
            this.checkFile = [];
            this.lrCheckPierfoundation = []; // 基桩检测表格信息集合
            getPierProjectTaskLists({
                    fId: this.equipmentDetailId
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.samllTable = res.data;
                        this.equipmentDetailIds = res.data[0].fId;
                        this.getPierTaskByFid(res.data[0].fId);
                    } else {

                        this.$message.error({
                            content:"检测任务信息列表 获取失败"+ res.msg,
                            duration: 1000
                        });
                    }
                })
                .catch(() => {
                    console.log("检测任务信息列表 获取失败");
                    return false;
                });
        },
        getPierTaskByFid(id) {
            this.lrCheckPiertask = {};
            this.checkFile = [];
            this.lrCheckPierfoundation = []; // 基桩检测表格信息集合
            getPierTaskByFid({
                    fId: id
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.lrCheckPiertask = res.data.lrCheckPiertask; // 任务主表信息
                        this.checkFile = res.data.checkFile;
                        this.lrCheckPierfoundation =
                            res.data.lrCheckPiertask.pierfoundationList; // 基桩检测表格信息集合
                    } else {
                        this.$message.error({
                            content:"基桩检测表格信息  获取失败"+ res.msg,
                            duration: 1000
                        });
                    }
                })
                .catch(() => {
                    console.log("基桩检测表格信息集合  获取失败");
                    return false;
                });
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val;
        },

        // 获取列表数据
        yj_searchForm(data) {
            this.loading = true;
            this.getPierProjectStatisticInfo()
            var that = this;
            window.sessionStorage.setItem(
                "GxEmbedded_pcManage_getList",
                JSON.stringify(data)
            );
            var id;
            if(data.fCompanyid!=''){
              id=data.fCompanyid
            }else {
              id=data.fprojectid
            }
            var obj = {
                fprojectid: data.fprojectid,
                fCompanyid: id, //机构id
                fUserid: data.fUserid, //当前登录用户id
                sublevel: "1", //查看下级  1是0否
                page: data.page, //页码
                pageSize: data.pageSize, //每页条数
                keyWord: data.keyWord, // 选择状态
            }
            getPierProjectPageLists(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        var arr1 = res.data.pierProjectInfo.list;

                        // that.tableData = res.data.pierProjectInfo.list;
                        // this.queryCriteriaData = res.data.pierProjectInfo;
                        var obj1 = {
                            modelType: "0", // 0代办 1已办
                            fUserid: data.fUserid, //当前登录用户id
                            page: data.page, //页码
                            pageSize: data.pageSize, //每页条数
                        }
                        getPierProjectPageList(obj1)
                            .then((res) => {
                                if (res.errcode == 0) {

                                    const arr2 = res.data.pierProjectInfo.list
                                    this.tableData = [...arr2, ...arr1];
                                    // that.tableData = res.data.pierProjectInfo.list;
                                    // this.queryCriteriaData = res.data.pierProjectInfo;
                                    // this.navigatepageNums =
                                    //     this.queryCriteriaData.navigatepageNums.length;
                                } else {
                                    // this.$message.error("获取列表数据", res.msg);
                                    this.loading = false;
                                    return false;
                                }
                            })
                            .catch(() => {
                                console.log("获取列表数据失败");
                                this.loading = false;
                            });


                    } else {
                        this.$message.error({
                            content:"列表数据获取失败"+ res.msg,
                            duration: 1000
                        });
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error({
                        content:"列表数据获取失败"+error.msg,
                        duration: 1000
                    });
                    this.loading = false;
                });
        },
        // 下面图表
        getPierProjectStatisticInfo() {
            var data = {
                fCompanyid: this.getList.fCompanyid,
                fUserid: this.getList.fUserid,
                sublevel: this.getList.sublevel,
                keyWord: this.getList.keyWord,
            };
            getPierProjectStatisticInfo(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.statisticInfo = res.data.statisticInfo[0]; //左侧基桩统计信息
                        this.rateInfo = res.data.monthRateInfo; //右侧折线图数据
                    } else {
                        this.$message.error("右侧折线图数据", res.msg);
                    }
                })
                .catch((err) => {
                    console.log("右侧折线图数据", err);
                });
        },

        // 点击当前行
        getRowInfo(e) {
            this.equipmentDetailId = e.F_Id;
        },

        // 点击报告编码
        openDialog(row) {
            this.equipmentDetailId = row.F_Id;
            this.edit(1);
            this.getPierProjectTaskLists();
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
    },
};